package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CurriculumTable;
import cn.wolfcode.crm.query.CurriculumTableQueryObject;
import cn.wolfcode.crm.service.ICurriculumTableService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("curriculumTable")
public class CurriculumTableController {
    @Autowired
    private ICurriculumTableService curriculumTableService;

    /*创建一个方法来确定*/
    @RequiresPermissions("curriculumTable:index")
    @PermissionName("课程表首页")
    @RequestMapping("index")
    public String index(){
        //查找到并共享
        return "curriculumTable/list";
    }
    @RequiresPermissions("curriculumTable:list")
    @PermissionName("课程表列表")
    @ResponseBody
    @RequestMapping("list")
    public PageResult list(Model model, @ModelAttribute("qo")CurriculumTableQueryObject qo){
        return curriculumTableService.query(qo);
    }

    /**
     *
     * @param curriculumTable 保存课程表
     * @return 返回json
     */
    @RequiresPermissions("curriculumTable:save")
    @PermissionName("课程表保存")
    @ResponseBody
    @RequestMapping("save")
    public JsonResult save(CurriculumTable curriculumTable){
        JsonResult result = new JsonResult();
        try {
            curriculumTableService.insert(curriculumTable);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("保存失败");
        }
        return result;
    }
    @RequiresPermissions("curriculumTable:update")
    @PermissionName("课程表更新")
    @ResponseBody
    @RequestMapping("update")
    public JsonResult update(CurriculumTable curriculumTable){
        JsonResult result = new JsonResult();
        try {
            curriculumTableService.updateByPrimaryKey(curriculumTable);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("更新失败");
        }
        return result;
    }
    //删除课程表
    @RequiresPermissions("curriculumTable:changeState")
    @PermissionName("课程表删除")
    @ResponseBody
    @RequestMapping("changeState")
    public JsonResult changeState(Long id){
        JsonResult result = new JsonResult();
        try {
            curriculumTableService.changeState(id);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("删除失败");
        }
        return result;
    }



}
